package com.example.doufacedemo

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.util.Log
import android.view.SurfaceHolder
import android.view.SurfaceView

class WxPaySurfaceView(context: Context?, attrs: AttributeSet?) : SurfaceView(context, attrs),
    SurfaceHolder.Callback {
    private var height: Int? = null

    init {
        this.isFocusable = true
        this.isFocusableInTouchMode = true
        holder.addCallback(this)
    }

    override fun surfaceChanged(holder: SurfaceHolder?, format: Int, width: Int, height: Int) {

    }

    override fun surfaceDestroyed(holder: SurfaceHolder?) {
        Log.e("onDraw", "surface 销毁")
    }

    override fun surfaceCreated(holder: SurfaceHolder?) {
        Log.e("onDraw", "surface创建成功")
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        val widthSize = MeasureSpec.getSize(widthMeasureSpec)
        height = widthSize
    }


    
//    override fun onDraw(canvas: Canvas?) {
//
//        val paint = Paint()
//        paint.color = Color.GREEN
//        paint.strokeWidth = 2f
//        paint.style = Paint.Style.STROKE
//        paint.isAntiAlias = true
//        canvas?.drawCircle(
//            height!! / 2.toFloat(),
//            height!! / 2.toFloat(),
//            height!! / 2.toFloat(), paint
//        )
//        super.onDraw(canvas)
//    }

    override fun draw(canvas: Canvas) {
        super.draw(canvas)

        Log.e("onDraw", "draw: test")
        val path = Path()
        path.addCircle(
            height!! / 2.toFloat(),
            height!! / 2.toFloat(),
            height!! / 2.toFloat(),
            Path.Direction.CCW
        )

        canvas.clipPath(path, Region.Op.REPLACE)


    }
}